'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    const token = ctx.app.jwt.sign(
      { ...ctx.request.body },
      this.app.config.jwt.secret
      // {
      //   expiresIn: '999m', // 时间根据自己定，具体可参考jsonwebtoken插件官方说明
      // }
    );
    ctx.body = {
      code: 1000,
      token,
    };
  }

  async login() {
    const { ctx } = this;
    const token = ctx.app.jwt.sign(
      { ...ctx.request.body },
      this.app.config.jwt.secret,
      {
        expiresIn: '999m', // 时间根据自己定，具体可参考jsonwebtoken插件官方说明
      }
    );
    ctx.body = {
      code: 1000,
      status: 'ok',
      type: '1',
      currentAuthority: 'admin',
      token,
    };
  }

  async outLogin() {
    const { ctx } = this;
    ctx.body = {
      data: {},
      success: true,
    };
  }

  async currentUser() {
    const { ctx } = this;
    ctx.body = {
      code: 1000,
      success: true,
      data: {
        name: 'Jidahan',
        avatar:
          'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
        userid: '00000001',
        email: '2529699061@qq.com',
        signature: '海纳百川，有容乃大',
        title: '前端开发工程师',
        group: '北京知新树-前端',
        tags: [
          {
            key: '0',
            label: '很有想法的',
          },
          {
            key: '1',
            label: '专注设计',
          },
          {
            key: '3',
            label: '大长腿',
          },
          {
            key: '5',
            label: '海纳百川',
          },
        ],
        notifyCount: 12,
        unreadCount: 11,
        country: 'China',
        access: '',
        geographic: {
          province: {
            label: '陕西省',
            key: '330000',
          },
          city: {
            label: '西安市',
            key: '330100',
          },
        },
        address: '莲湖区枣园',
        phone: '0752-268888888',
      },
    };
  }
}

module.exports = HomeController;
